package summarizer.newversion;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

import thesis.DataObject;
import thesis.Summary;

public class FileSummarizer extends Summarizer {
	public static String fileName = "res/recordedSummary/summary.txt";

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void recordSummary(Summary sum) throws IOException {
		BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
		for (DataObject obj : sum.getMemoryTweets()) {
			bw.write(obj.getDbId() + "\n");
		}
		bw.close();

	}

	@Override
	public Summary computeSummary(int summaryDimension, int numberOfPages,
			HashMap<Long, DataObject> tweets, int dimSize) {
		BufferedReader br;
		Summary summary = new Summary();
		try {
			br = new BufferedReader(new FileReader(fileName));
			String line = null;
			int count = 0;
			while ((line = br.readLine()) != null && count <summaryDimension) {
				long id = Long.parseLong(line);
				summary.addMemoryTweet(tweets.get(id));
				count++;
			}
			br.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return summary;
	}

	@Override
	public long getExecutionTime() {
		// TODO Auto-generated method stub
		return 0;
	}
	public String toString(){
		return "File Summarizer";
	}

}
